/*
 * @lc app=leetcode.cn id=104 lang=typescript
 *
 * [104] 二叉树的最大深度
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     val: number
 *     left: TreeNode | null
 *     right: TreeNode | null
 *     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.left = (left===undefined ? null : left)
 *         this.right = (right===undefined ? null : right)
 *     }
 * }
 */

function maxDepth(root: TreeNode | null): number {
    let res: number = 0;
    if (!root) {
        return res;
    }
    const q: any = [];
    q.push(root)
    while (q.length !== 0) {
        const size = q.length;
        res++;
        for (let i = 0; i < size; i++) {
            const node = q.shift();
            if (node.left) {
                q.push(node.left)
            }
            if (node.right) {
                q.push(node.right)
            }

        }
    }
    return res
};
// @lc code=end

